/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package testfile;

/**
 *
 * @author Victor Alvarez
 */
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import java.io.IOException;

class TestFile {

    public static void main(String[] arg) {
        boolean done = false;
        BasicFile f = null;
        
        // the menu
        String menu = "Enter option\n1. Open File\n.......\n.......\nMORE MENU CASES TO COME\n.......\n..........\n4.Quit";
        while (!done) {
            
            String s = JOptionPane.showInputDialog(menu);
            
            try {
                int i = Integer.parseInt(s);
                switch (i) {
                    //Opens file and saves a backup
                    case 1:
                        //created a BasicFile object
                        f = new BasicFile();
                        
                        display(f.getContents());
                        //used for errors
                        
                        
                        
                        break;
                    /*
                     *.
                     *.You are responsible for any other cases
                     *.
                     */
                    case 4:
                        done = true;
                        break;
                    default:
                        display("This option is underfined", "Error");
                        break;
                }
            } catch (NumberFormatException | NullPointerException e) //| IOException e)
            {
                display(e.toString(), "Error");
            }
        }
    }

    public static void display(String s, String err) {
        JOptionPane.showMessageDialog(null, s, err, JOptionPane.ERROR_MESSAGE);
    }

    public static void display(String s) {
        JOptionPane.showMessageDialog(null, s, "Content", JOptionPane.ERROR_MESSAGE);
    }
    public static void display(BasicFile f) {
        String s = f.getFileSize() + " bytes" + "\n" + f.getPath();
        String fn = f.getName();
        JOptionPane.showMessageDialog(null, s, "Filename: " + fn, JOptionPane.INFORMATION_MESSAGE);
    }
}
